package com.kum.domain.constant;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;

/**
 * @version V1.0
 * @Package com.kum.domain.constant
 * @auhter 枯木Kum
 * @date 2021/3/10-11:07 AM
 */
public class Sign {
    /**
     * Redis中的key固定前缀
     */
    public static final String kEY = "SIGN:";
    /**
     * 签到类型:早上
     */
    public static final String MORNING = "M";
    /**
     * 签到类型:下午
     */
    public static final String AFTERNOON = "A";
    /**
     * 签到类型:晚上
     */
    public static final String NIGHT = "N";
    /**
     * 根据当前周去查询签到排行榜
     */
    public static final String CURRENT_WEEK_SIGN = "week";
    /**
     * 根据当前月去查询签到排行榜
     */
    public static final String CURRENT_MONTH_SIGN = "month";
    /**
     * 获取当前签到时间的类型
     * @return 分别对应:早上、下午、晚上三个时间段签到。
     */
    public static String getCurrentSginTimeType(){
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(new Date());
        int hour = calendar.get(Calendar.HOUR_OF_DAY);
        if(hour < 12){
            return MORNING;
        }else if(hour < 17){
            return AFTERNOON;
        }
        return NIGHT;
    }

    /**
     * 分别获取本月的起始天和结束天
     * @return 「start」and 「end」
     */
    public static HashMap<String, String> getMonthStartAndEndTime(){
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        HashMap<String, String> map = new HashMap<>();
        Calendar cal = Calendar.getInstance();
        cal.set(Calendar.DAY_OF_MONTH, 1);
        map.put("start",sdf.format(cal.getTime()));
        cal.set(Calendar.DATE, 1);
        cal.add(Calendar.MONTH, 1);
        cal.add(Calendar.DATE, -1);
        map.put("end",sdf.format(cal.getTime()));
        System.out.println("start" + map.get("start"));
        System.out.println("end" + map.get("end"));
        return map;
    }

    /**
     * 分别获取本周的起始天和结束天
     * @return 「start」and 「end」
     */
    public static HashMap<String, String> getWeekStartAndEndTime(){
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        HashMap<String, String> map = new HashMap<>();
        Calendar cal = Calendar.getInstance();
        cal.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY);
        map.put("start",sdf.format(cal.getTime()));
        cal.add(Calendar.DAY_OF_MONTH, 6);
        map.put("end",sdf.format(cal.getTime()));
        return map;
    }

    public static void main(String[] args) {
        getMonthStartAndEndTime();
    }
}
